package com.whnk.job.util;//package com.whnk.quartz.util;
//
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.http.HttpHeaders;
//import org.springframework.http.HttpMethod;
//import org.springframework.http.HttpStatus;
//import org.springframework.http.ResponseEntity;
//import org.springframework.http.client.SimpleClientHttpRequestFactory;
//import org.springframework.stereotype.Component;
//import org.springframework.web.client.RestTemplate;
//
//import java.text.MessageFormat;
//import java.util.HashMap;
//
//@Component
//public class RestfulHandler {
//    private final Logger logger = LoggerFactory.getLogger(ConnectionUtil.class);
//
//    private RestTemplate restTemplate;
//
//    public RestfulHandler() {
//        initRestTemplate();
//    }
//
//    private void initRestTemplate() {
//        SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
//        requestFactory.setConnectTimeout(30000);// 设置连接超时，单位毫秒
//        requestFactory.setReadTimeout(30000);  //设置读取超时
//        restTemplate = new RestTemplate();
//        restTemplate.setRequestFactory(requestFactory);
//        logger.info("RestTemplate init successful");
//    }
//
//    public ResponseEntity getData(String restfulUrl, HashMap<String, Object> params, HttpMethod method, String cookie) {
//        logger.info(MessageFormat.format("restfulUrl:{0}, method:{1}", restfulUrl, method));
//        ResponseEntity<String> response;
//        if (params == null) {
//            response = restTemplate.exchange(restfulUrl, method, null, String.class);
//        } else {
//            response = restTemplate.exchange(restfulUrl, method, null, String.class, params);
//        }
//        HttpHeaders headers = new HttpHeaders();
//        headers.add(HttpHeaders.COOKIE, cookie);
//        headers.add(HttpHeaders.ACCEPT_CHARSET, "UTF-8");
//
//        if (response.getStatusCode() == HttpStatus.OK) {
//            return response;
//        }
//        logger.error("response code:" + response.getStatusCodeValue());
//        return null;
//    }
//}
